//
//  photoScroll.m
//  timemovie
//
//  Created by Yiqiao on 15/7/23.
//  Copyright (c) 2015年 Yiqiao. All rights reserved.
//

#import "photoScroll.h"
#import "UIImageView+WebCache.h"
#define w [UIScreen mainScreen].bounds.size.width
#define h [UIScreen mainScreen].bounds.size.height
#define navH 64;
#define barH 49;
@implementation photoScroll

- (void)doubleTap{

    if (self.zoomScale ==1) {
        [self setZoomScale:3];
    }
    else{
        [self setZoomScale:1];
    }
}

- (void)singleTap{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"hidden" object:nil];

}

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _imageView = [[UIImageView alloc ]initWithFrame:CGRectMake(0, -64, w, h)];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
        
        self.delegate = self;
        
        self.minimumZoomScale = 0.5;
        self.maximumZoomScale = 2;

        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap)];
        
        doubleTap.numberOfTapsRequired = 2;
        doubleTap.numberOfTouchesRequired = 1;
        [self addGestureRecognizer:doubleTap];
        
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap)];
        
        
        [self addGestureRecognizer:singleTap];
        
        [singleTap requireGestureRecognizerToFail:doubleTap];
    
    }
    return self;
}

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    UIView *view = self.imageView;
    return view;
}


- (void)setImageUrl:(NSString *)imageUrl{

    _imageUrl = imageUrl;
    [self setNeedsLayout];
}


- (void)layoutSubviews{
    [_imageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrl]];
    NSLog(@"%@" ,self.imageUrl);
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
